import asyncio
import time
from config import LiveConfig
import aiohttp
import requests


async def get_data(url):
    connector = aiohttp.TCPConnector(verify_ssl=False)
    async with aiohttp.ClientSession(connector=connector) as session:
        async with session.get(url) as resp:
            if resp.status == 200:
                try:
                    data = await resp.json()
                except aiohttp.client_exceptions.ContentTypeError:
                    data = None
                return data


def start_request(url):
    response = requests.get(url)
    try:
        data = response.json()
    except ValueError:
        data = None
    return data


loop = asyncio.get_event_loop()
_urls = [LiveConfig.ACTION['GET_LIST'] + '&page=' + str(_) for _ in range(1, 8)]
tasks = [asyncio.ensure_future(get_data(_)) for _ in _urls]
start = time.time()
loop.run_until_complete(asyncio.gather(*tasks))
end = time.time()
print('diff1', (end - start) * 1000)
# results = [_.result() for _ in tasks]
# print(results)

